{include file="header/index" /}
<div class="newContentBox">
    <ul class="topTitle" role="tablist">
        <li><i class="fa fa-bars topTitleFa"></i></li>
        <li role="presentation" class="active tab" id="tab1" onclick="nav_lis(this)">
            <a href="#user" aria-controls="user" role="tab" data-toggle="tab">用户组管理</a>
            <span class="topTitleLabel">|</span>
        </li>
        <li role="presentation" class="tab" id="tab2" onclick="nav_lis(this)">
            <a href="#admin" aria-controls="admin" class="profile" role="tab" data-toggle="tab">管理员管理</a>
            <span class="topTitleLabel">|</span>
        </li>
        <li role="presentation" class="tab" id="tab3" onclick="nav_lis(this)">
            <a href="#menu" aria-controls="menu" role="tab" data-toggle="tab">系统菜单栏管理</a>
        </li>
        <!-- <li role="presentation" class="tab" id="tab4" onclick="nav_lis(this)">
            <a href="#dbbackup" aria-controls="dbbackup" role="tab" data-toggle="tab">数据库备份</a>
        </li>
        <li role="presentation" class="tab" id="tab5" onclick="nav_lis(this)">
            <a href="#dbrestore" aria-controls="dbrestore" role="tab" data-toggle="tab">数据库还原</a>
        </li> -->
    </ul>
    <div class="admin_nr">
        <!--用户组管理-->
        <div id="user">
            <!-- 用户组列表 及按钮 -->
            <div class="newListPart">
                <div class="newTitleBox">
                    <span class="layui-inline newListTitle">用户组列表</span>
                    <div class="layui-inline newTitleBtnBox">
                        <a href="{:url('Authgroup/add')}" class="newBtnDefault newBtnPrimary">
                            <i class="fa fa-plus addIcon"></i>&nbsp;&nbsp;添加用户组
                        </a>
                    </div>
                </div>
                <div class="newTableBox">
                    <table class="layui-table">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>用户组名称</th>
                                <th>角色</th>
                                <th>状态</th>
                                <th>添加时间</th>
                                <th>更新时间</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {foreach $data as $v}
                            <tr>
                                <td>{$v.id}</td>
                                <td>{$v.title}</td>
                                <td>{$v.role_name}</td>
                                <td>
                                    <?php if($v['id'] != 1){?>
                                    {if condition="$v['status'] eq 1"}
                                    <div id="zt8" onclick="role_state(this, {$v.id})"><span
                                            class="label label-info">开启</span></div>
                                    {else /}
                                    <div id="zt8" onclick="role_state(this, {$v.id})"><span
                                            class="label label-danger">关闭</span></div>
                                    {/if}
                                    <?php }?>
                                </td>
                                <td>{:date('Y-m-d H:i:s',$v.add_time)}</td>
                                <td>{:date('Y-m-d H:i:s',$v.update_time)}</td>
                                <td>
                                    <?php if($v['id'] != 1){?>
                                    <a href="javascript:;" onclick="giveQx(this)" class="newBtnDefault"
                                        data-authority-id="{$v['id']}">权限分配</a>&nbsp;&nbsp;
                                    <a href="{:url('Authgroup/edit',array('id'=>$v['id']))}" class="newBtnDefault">
                                        编辑</a>&nbsp;&nbsp;
                                    <!-- <a href="javascript:;" onclick="roleDel(this)" class="btn btn-danger btn-xs"> <i class="fa fa-trash-o"></i> 删除</a> -->
                                    <?php }?>
                                </td>
                            </tr>
                            {/foreach}
                        </tbody>
                    </table>
                    <div class="pageBox">
                        <div class="authPage">
                            第1页,共1页
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <!--管理员管理-->
        <div class="hides" id="admin">
            <!-- 管理员列表 及按钮 -->
            <div class="newListPart">
                <div class="newTitleBox">
                    <span class="layui-inline newListTitle">管理员列表</span>
                    <div class="layui-inline newTitleBtnBox">
                        <a href="{:url('Users/addUser')}" class="newBtnDefault newBtnPrimary">
                            <i class="fa fa-plus addIcon"></i>&nbsp;&nbsp;添加管理员
                        </a>
                    </div>
                </div>
                <div class="newTableBox">
                    <table class="layui-table">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>管理员名称</th>
                                <th>头像</th>
                                <th>管理员角色</th>
                                <th>登录次数</th>
                                <th>上次登录ip</th>
                                <th>上次登录时间</th>
                                <th>真实姓名</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {foreach $admin_data as $v}
                            <tr>
                                <td>{$v.id}</td>
                                <td>{$v.account}</td>
                                <td><img class="user-img" src="{$v.avatar_img}"
                                        onerror="this.src='__IMG__/default.jpg'">
                                </td>
                                <td>{$v.title}</td>
                                <td>{$v.loginnum}</td>
                                <td>{$v.last_login_ip}</td>
                                <td>{:date('Y-m-d H:i:s',$v.last_login_time)}</td>
                                <td>{$v.name}</td>
                                <td>
                                    <?php if($v['is_admin'] != 1){ ?>
                                    {if condition="$v['status'] eq 1"}
                                    <div id="zt8" onclick="role_state(this, {$v.id})"><span
                                            class="label label-info">开启</span></div>
                                    {else /}
                                    <div id="zt8" onclick="role_state(this, {$v.id})"><span
                                            class="label label-danger">关闭</span></div>
                                    {/if}
                                    <?php }?>
                                </td>
                                <td>
                                    <?php if($v['is_admin'] != 1){ ?>
                                    <a href="{:url('Users/updateUser',array('id'=>$v['id']))}"
                                        class="newBtnDefault">编辑</a>&nbsp;&nbsp;
                                    <a href="javascript:;" onclick="roleDel(this, {$v.id})"
                                        class="newBtnDefault newBtnRed">删除</a>
                                    <?php }?>
                                </td>
                            </tr>
                            {/foreach}
                        </tbody>
                    </table>
                    <div class="pageBox">
                        <div class="authPage">
                            第1页,共1页
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <!--菜单栏管理-->
        <div class="hides" id="menu">
            <!-- 菜单列表 及按钮 -->
            <div class="newListPart">
                <div class="newTitleBox">
                    <span class="layui-inline newListTitle">菜单列表</span>
                    <div class="layui-inline newTitleBtnBox">
                        <a href="#" onclick="menuopen()" class="newBtnDefault newBtnPrimary">
                            <i class="fa fa-plus addIcon"></i>&nbsp;&nbsp;添加菜单
                        </a>
                    </div>
                </div>
                <div class="newTableBox">
                    <table class="layui-table">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>权限名称</th>
                                <th>节点</th>
                                <th>菜单状态</th>
                                <th>是否菜单</th>
                                <th>添加时间</th>
                                <th>排序</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {foreach $menu_data as $v}
                            <tr>
                                <td>{$v.id}</td>
                                <td
                                    style='text-align:left;padding-left:{if condition="$v.leftpin neq 0"}{$v.leftpin}px{/if}'>
                                    {$v.lefthtml}{$v.title}</td>
                                <td>{$v.url}</td>
                                <td>
                                    {if condition="$v['status'] eq 1"}
                                    <div id="zt8" onclick="rule_state(this, {$v.id})"><span
                                            class="label label-info">开启</span></div>
                                    {else /}
                                    <div id="zt8" onclick="rule_state(this, {$v.id})"><span
                                            class="label label-danger">关闭</span></div>
                                    {/if}
                                </td>
                                <td>
                                    {if condition="$v['menutitle'] eq 1"}
                                    <div id="zt8" onclick="role_menutitle(this,{$v.id})"><span
                                            class="label label-info">是</span></div>
                                    {else /}
                                    <div id="zt8" onclick="role_menutitle(this,{$v.id})"><span
                                            class="label label-danger">否</span></div>
                                    {/if}
                                </td>
                                <td>{:date('Y-m-d H:i:s',$v.add_time)}</td>
                                <td><input class="t_center sort-input" type="text" value="{$v.sort}" name="sort"
                                        onchange="ModifyTheSort(this, {$v.id})"></td>
                                <td>
                                    <a href="{:url('Menu/ModifyTheSort',array('id'=>$v['id']))}" class="newBtnDefault">
                                        编辑</a>&nbsp;&nbsp;
                                    <a href="javascript:;" onclick="ruleDel(this, {$v.id})"
                                        class="newBtnDefault newBtnRed"> 删除</a>
                                </td>
                            </tr>
                            {/foreach}
                        </tbody>
                    </table>
                    <div class="pageBox">
                        <div class="authPage">
                            第1页,共1页
                        </div>
                    </div>
                </div>
            </div>

        </div>

        <!--数据库备份-->
        <!-- <div class="hides" id="dbbackup">
            <div class="newListPart">
                <div class="newTitleBox">
                    <span class="layui-inline newListTitle">数据库列表</span>
                    <div class="layui-inline newTitleBtnBox">
                        <button class="backup" onclick="backup();">立即备份</button>
                        <button class="optimization">优化表</button>
                        <button class="repair">修复表</button>
                    </div>
                </div>
                <div class="newTableBox">
                    <form id="export-form" method="post" action="">
                        <table class="layui-table">
                            <thead>
                                <tr>
                                    <th><input type="checkbox" name="all" value=""></th>
                                    <th>表名</th>
                                    <th>数据量</th>
                                    <th>数据大小</th>
                                    <th>创建时间</th>
                                    <th>备份状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {foreach $dbbackup_data as $k => $v}
                                <tr>
                                    <td><input type="checkbox" class="Subpage" name="ids[]" value="{$v.name}"
                                            checked="chedked"></td>
                                    <td>{$v.name}</td>
                                    <td>【{$v.rows}】条记录</td>
                                    <td>{$v.data_length|format_bytes}</td>
                                    <td>{$v.create_time}</td>
                                    <td id="info">等待备份...</td>
                                    <td>
                                        <button type="button" class="operatOptimi"
                                            onclick="optimizeOne('{$v.name}', this)">优化表</button>
                                        <button type="button" class="operatRepair"
                                            onclick="repairOne('{$v.name}', this)">修复表</button>
                                    </td>
                                </tr>
                                {/foreach}
                            </tbody>
                        </table>
                    </form>
                    <div class="pageBox">
                        <div class="authPage">
                            第1页,共1页
                        </div>
                    </div>
                </div>
            </div>
        </div> -->
        <!--数据库还原-->
        <!-- <div class="hides" id="dbrestore">
            <div class="newListPart">
                <div class="newTitleBox">
                    <span class="layui-inline newListTitle">数据库还原</span>
                </div>
                <div class="newTableBox">
                    <table class="layui-table">
                        <thead>
                            <tr>
                                <th>备份名称</th>
                                <th>卷数</th>
                                <th>压缩</th>
                                <th>数据大小</th>
                                <th>备份时间</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {foreach $dbrestore_data as $key => $vo}
                            <tr>
                                <td>{$vo.time|date='Ymd-His',###}</td>
                                <td>{$vo.part}</td>
                                <td>{$vo.compress}</td>
                                <td>{$vo.size|format_bytes}</td>
                                <td>{$key}</td>
                                <td>
                                    <button class="operatOptimi db-import" data-time="{$vo.time}">还原</button>
                                    <button class="operatRepair" onclick="del(this, {$vo.time})">删除</button>
                                </td>
                            </tr>
                            {/foreach}
                        </tbody>
                    </table>

                    <div class="pageBox">
                        <div class="authPage">
                            第1页,共1页
                        </div>
                    </div>
                </div>
            </div>
        </div> -->
    </div>
</div>

<script>
    var layer = layui.layer,
        element = layui.element,
        laydate = layui.laydate,
        laypage = layui.laypage,
        form = layui.form,
        laytpl = layui.laytpl;



    //model高度自适应
    $(document).ready(function () {
        var height = window.screen.availHeight;
        $(".quanxian").css("height", height * 0.7);
        $(".quanxian-content").css("height", height * 0.65);
        $('.quanxian').css('top', '100px');
    });

    //状态开启关闭
    function role_state(obj, id) {
        $.post("{:url('Authgroup/updateStatus')}", {
            id: id
        }, function (e) {
            if (e.code == '1') {
                parent.layer.msg(e.msg, {
                    icon: 1,
                    time: 2000
                });
                if ($(obj).find("span").hasClass("label-info")) {
                    $(obj).find("span").addClass("label-danger")
                    $(obj).find("span").removeClass("label-info");
                    $(obj).find("span").text("关闭");
                } else {

                    $(obj).find("span").removeClass("label-danger")
                    $(obj).find("span").addClass("label-info");
                    $(obj).find("span").text("开启")

                }
            }
        }, 'json')
    }
    //开启权限分配
    function giveQx(obj) {
        var id = $(obj).attr('data-authority-id');
        console.log('id',id)
        var html = '';
        html += '<form class="layui-form popBox" name="add_rule" id="add_rule" action="" method="post"  >';
        html += '<div id="" class="quanxian-content" style="overflow: auto;">';
        html += '<div class="left new_style" style="" id="">';
        html += '<div class="all_choose"> <input lay-skin="primary" type="checkbox" value="" name="allLevel" lay-filter="allauthority" > 全部</div>';
        html += '<div class="right_box">';
        {foreach $rule as $key => $val}
        html += '<div class="list_one per_class" data-id='+id+'>';
        html += '<div class="classif_left">';
        html += '<input type="checkbox" lay-skin="primary" name="oneLevel" lay-filter="author_ityfun" value="{$val.id}">{$val.title}';
        html += '</div>';
        html += '<div class="classif_right">';
        <?php if(!empty( $val['child'])){?>
        {foreach $val['child'] as $kk => $vv}
        html += '<div class="right_centerone">';
        html += '<div class="left_type">';
        html += '<div class="little_title">';
        html += '<input name="tweLevel" type="checkbox" lay-skin="primary" value="{$vv.id}" lay-filter="twoLevel">{$vv.title}：';
        html += '</div>';
        html += '</div>';
        html += '<div class="right_type">';
        <?php if(!empty($vv['levels'])){?>
        {foreach $vv['levels'] as $k =>$v}
        html += '<div class="type_one">';
        html += '<input name="threeLevel" class="fl" type="checkbox" lay-skin="primary" value="{$v.id}" lay-filter="threeLevel">{$v.title}';
        html += '</div>';
        {/foreach}
        <?php }?>
        html += '</div>';
        html += '</div>';
        {/foreach}
        <?php }?>
        html += '</div>';
        html += '</div>';
        {/foreach}
        html += '</div>';        
        html += '</div>';
        html += '</div>';
        html += '</form>';

        parent.layer.open({
            title: '权限分配',
            type: 1,
            area: ['823px', '490px'], //宽高
            shadeClose: true, //点击遮罩关闭
            content: html,
            btn: ['确认', '取消'],
            btnAlign: 'c',
            success: function (layero, index) {
                $.post("{:url('Authgroup/AjaxAuthority')}", { id: id }, function(e) {
                    var inputObj = $(layero).find('.per_class').find('input');
                    $.each(e.data, function(key, val) {
                        $.each(inputObj, function(kk, vv) {
                            if ($(vv).val() == val) {
                                $(vv).prop("checked", true);
                            }
                        })
                    })
                    parent.form.render();
                }, 'json');
                parent.form.render();
                // 点击一级
                parent.form.on('checkbox(allauthority)',function(data){
                    console.log('点击了全部');
                    console.log(data);
                    var checked = data.elem.checked;
                    if(checked){
                        $(layero).find(".per_class").find("input").prop("checked", true)
                    }else{
                        $(layero).find(".per_class").find("input").prop("checked", false)
                    }
                    parent.form.render();

                })
                // 点击二级
                parent.form.on('checkbox(author_ityfun)',function(data){
                    console.log('点击了二级');
                    console.log(data);
                    var elem = data.elem;
                    var checked = data.elem.checked;
                    var inputAll = $(layero).find(".classif_left").find("input").length;
                    if(checked){
                        $(elem).parents(".classif_left").siblings(".classif_right").find("input").prop("checked", true)
                    }else{
                        $(elem).parents(".classif_left").siblings(".classif_right").find("input").prop("checked", false)
                    }
                    var All = 0;
                    for (var i = 0; i < inputAll; i++) {
                        if ($(layero).find(".classif_left").find("input").eq(i).is(":checked")) {
                            All++
                        }
                    }
                    console.log('长度2', All);
                    if (All == inputAll) {
                        //console.log('全都要');
                        $(layero).find("input[name='allLevel']").prop("checked", true);
                    } else {
                        // console.log('缺一个');
                        $(layero).find("input[name='allLevel']").prop("checked", false);
                    }
                    parent.form.render();

                })
                // 点击三级
                parent.form.on('checkbox(twoLevel)',function(data){
                    console.log('点击了三级');
                    var elem = data.elem;
                    var checked = data.elem.checked;
                    var tweLevel = $(elem).parents(".per_class").find("input[name='tweLevel']").length;
                    var threeLevel = $(elem).parents(".per_class").find("input[name='threeLevel']").length;
                    var inputAll = $(layero).find(".per_class").find("input").length;
                    if(checked){
                        $(elem).parents(".right_centerone").find("input[name='threeLevel']").prop("checked", true)
                        $(elem).parents(".right_centerone").find("input[name='oneLevel']").prop("checked", true)
                    }else{
                        $(elem).parents(".right_centerone").find("input[name='threeLevel']").prop("checked", false)
                    }

                    var threeall = 0
                    var threenumAll = 0
                    //三级
                    for (var j = 0; j < tweLevel; j++) {
                        if ($(elem).parents(".per_class").find("input[name='tweLevel']").eq(j).is(":checked")) {
                            threeall++
                        }
                    }
                    console.log('inputAll^_^', threeall);
                    //三级
                    for (var i = 0; i < inputAll; i++) {
                        if ($(layero).find(".per_class").find("input").eq(i).is(":checked")) {
                            threenumAll++
                        }
                    }
                    console.log('threeall', threeall);
                    if (threeall > 0) {
                        $(elem).parents(".per_class").find("input[name='oneLevel']").prop("checked", true)
                    } else {
                        $(elem).parents(".per_class").find("input[name='oneLevel']").prop("checked", false)
                    }

                    if (threenumAll == inputAll) {
                        $(layero).find("input[name='allLevel']").prop("checked", true)
                    } else {
                        $(layero).find("input[name='allLevel']").prop("checked", false)
                    }
                    parent.form.render();

                })
                // 点击四级
                parent.form.on('checkbox(threeLevel)',function(data){
                    console.log('点击了四级');
                    var elem = data.elem;
                    var checked = data.elem.checked;
                    var thisArry = $(elem).parents(".type_one").length;
                    var thisAll = $(elem).parents(".per_class").find("input[name='tweLevel']").length;
                    var inputAll = $(layero).find(".per_class").find("input").length;
                    var count = 0;
                    var count2 = 0;
                    var all = 0
                    //循环当前三级里面的四级
                    for (var i = 0; i < thisArry; i++) {
                        if ($(layero).find(".right_centerone").find(".right_centerone").find("input").eq(i).is(":checked")) {
                            count++
                        }
                    }
                    for (var i = 0; i < inputAll; i++) {
                        if ($(elem).parents(".right_type").find("input").eq(i).is(":checked")) {
                            all++
                        }
                    }
                    //选中三级
                    if (count != 0 && all != 0) {
                        console.log(1);
                        $(elem).parents(".right_centerone").find("input[name='tweLevel']").prop("checked", true);
                        $(elem).parents(".per_class").find("input[name='oneLevel']").prop("checked", true)
                    } else if (count == 0 && all == 0) {
                        console.log(2);                      
                        $(elem).parents(".right_centerone").find("input[name='tweLevel']").prop("checked", false);
                        $(elem).parents(".per_class").find("input[name='oneLevel']").prop("checked", false)
                    } else if (count == 0 && all != 0) {
                        console.log(3);                      
                        $(elem).parents(".per_class").find("input[name='oneLevel']").prop("checked", true)
                        $(elem).parents(".right_centerone").find("input[name='tweLevel']").prop("checked", true);
                    } else if (count != 0 && all == 0) {
                        console.log(4);                      
                        $(elem).parents(".per_class").find("input[name='oneLevel']").prop("checked", true)
                        $(elem).parents(".right_centerone").find("input[name='tweLevel']").prop("checked", false);
                    }
                    //选中全选
                    if (all == inputAll) {
                        $(layero).find("input[name='allLevel']").prop("checked", true)
                    } else {
                        $(layero).find("input[name='allLevel']").prop("checked", false)
                    }
                    parent.form.render();

                })
            },
            yes: function (index, layero) {
                // var remarks = $(layero).find("#remarks").val();
                var inputObj = $(layero).find('.per_class').find('input');
                var rules = [];
                $.each(inputObj, function(key, val) {
                    if ($(val).is(':checked')) {
                        rules.push($(val).val());
                    }
                })
                var id =  $(layero).find('.per_class').attr('data-id');
                $.post("{:url('Authgroup/AddRules')}", { rules: rules, id: id }, function(e) {
                    if (e.code == 1) {
                        parent.layer.msg(e.msg, { icon: 1, time: 2000 }, function() {
                          //  window.location.href = e.data;
                           parent.layer.closeAll();
                        });
                    } else {
                        parent.layer.msg(e.msg, { icon: 2, time: 2000 });
                    }
                }, 'json')

            },
            btn2: function (index, layero) {
                //按钮【按钮二】的回调
                // return false;//开启该代码可禁止点击该按钮关闭
            },
            cancel: function () {
                //右上角关闭回调
                //return false 开启该代码可禁止点击该按钮关闭
            }
        });
    }
    /**
     * 权限节点回选
     */


    /**
     * 提交
     */

    function nav_lis(obj) {
        var lis = $(obj).index() - 1;
        $(".tab").removeClass("active");
        $(obj).addClass('active');
        $(".admin_nr>div").eq(lis).show().siblings().hide()
    }
    $(function () {
        var lis = GetQueryString("type");
        console.log(lis);
        $(".admin_nr>div").eq(lis - 1).show().siblings().hide();
        $(".tab").removeClass("active");
        $("#tab" + lis).addClass("active");
        $(".db-import").click(function () {
            var time = $(this).attr('data-time');
            var url = "{:url('Data/revert')}?time=" + time;
            var self = this,
                status = ".";
            parent.layer.alert('确认还原数据?', {
                btn: ['确认', '取消'],
            }, function () {
                parent.layer.msg("正在还原数据库，请不要关闭！", {
                    icon: 1
                })
                $.get(url, success, "json");
                window.onbeforeunload = function () {
                    return "正在还原数据库，请不要关闭！";
                };
                return false;

                function success(data) {
                    if (data.code) {
                        if (data.data.gz) {
                            data.msg += status;
                            if (status.length === 5) {
                                status = ".";
                            } else {
                                status += ".";
                            }
                        }
                        $(self).parent().prev().text(data.msg);
                        if (data.data.part) {
                            $.get(url, {
                                "part": data.data.part,
                                "start": data.data.start
                            }, success, "json");
                        } else {
                            window.onbeforeunload = function () {
                                return null;
                            };
                        }
                    } else {
                        parent.layer.alert(data.msg, 0);
                    }
                }
            });
        });
    })



    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }
    //开启添加菜单
    function menuopen() {
        var html = '';
        html += '<form class="layui-form popBox" name="add_rule" id="add_rule" action="" method="post"  >';
        html += '<div class="popChoose">';
        html += '<div class="leftPop">所属父级：</div>';
        html += '<div class="rightPop">';
        html += '<div class="selectBox2">';
        html += '<select name="pid" id="pid">';
        html += '<option value="0">--默认顶级--</option>'; 
        {foreach $menu_data as $v}
        html += '<option value="{$v.id}" style="margin-left:55px;"> {$v.lefthtml}{$v.title}</option>'; 
        {/foreach}               
        html += '</select>';
        html += '</div>';
        html += '</div>';
        html += '</div>';

        html += '<div class="popChoose">';
        html += '<div class="leftPop">菜单名称：</div>';
        html += '<div class="rightPop">';
        html += '<div class="selectBox2">';
        html += '<input type="text" name="title" id="title" placeholder="输入菜单名称" class="layui-input">';
        html += '</div>';
        html += '</div>';
        html += '</div>';

        html += '<div class="popChoose">';
        html += '<div class="leftPop">CSS样式：</div>';
        html += '<div class="rightPop">';
        html += '<div class="selectBox2">';
        html += '<input type="text" name="css" id="css" placeholder="输入CSS样式" class="layui-input">';
        html += '<div class="authText">如：fa fa-user</div>';
        html += '</div>';
        html +=
            '<a class="seeIcon" href="http://fontawesome.dashgame.com/" target="_blank" target="_blank"><img src="__IMG__/icon17.png" width="12px" alt="">选择图标</a>';
        html += '</div>';
        html += '</div>';

        html += '<div class="popChoose">';
        html += '<div class="leftPop">节点：</div>';
        html += '<div class="rightPop">';
        html += '<div class="selectBox2">';
        html += '<input type="text" name="url" id="url" placeholder="模块/控制器/方法" class="layui-input">';
        html += '<div class="authText">如：administrative/user/index (一级节点添加“#”即可)</div>';
        html += '</div>';
        html += '</div>';
        html += '</div>';

        html += '<div class="popChoose">';
        html += '<div class="leftPop">排序：</div>';
        html += '<div class="rightPop">';
        html += '<div class="selectBox2">';
        html +=
            '<input type="text" name="sort" id="sort" value="50" placeholder="输入排序" class="layui-input">';
        html += '</div>';
        html += '</div>';
        html += '</div>';

        html += '<div class="popChoose">';
        html += '<div class="leftPop">是否显示在菜单栏：</div>';
        html += '<div class="rightPop">';
        html += '<div class="selectBox">';
        html += '<input type="hidden" name="menutitle" value="0">';
        html += '<input type="checkbox" name="menutitle" value="1" lay-skin="primary" checked> 默认是';
        html += '</div>';
        html += '<div class="leftPop">状态：</div>';
        html += '<div class="rightPop">';
        html += '<div class="selectBox">';
        html += '<input type="hidden" name="status" value="0">';
        html += '<input type="checkbox" name="status" value="1" lay-skin="primary" checked> 默认开启';
        html += '</div>';
        html += '</div>';
        html += '</div>';
        html += '</div>';

        html += '</form>';
        parent.layer.open({
            title: '添加菜单',
            type: 1,
            area: ['823px', '490px'], //宽高
            shadeClose: true, //点击遮罩关闭
            content: html,
            btn: ['确认', '取消'],
            btnAlign: 'c',
            success: function (layero, index) {
                parent.form.render();
            },
            yes: function (index, layero) {
                // var remarks = $(layero).find("#remarks").val();
                var sendData = {};
                var data = $(layero).find("#add_rule").serialize(); //序列化表单
                data.split('&').forEach(function (param) {
                    param = param.split('=');
                    sendData[param[0]] = decodeURI(param[1]);
                })
                console.log('sendData', sendData)
                if ($(layero).find("#title").val() == '') {
                    parent.layer.msg('菜单名不能为空', {
                        icon: 2,
                        time: 2000
                    });
                    return false;
                }

                if ($(layero).find("#url").val() == '') {
                    parent.layer.msg('节点不能为空', {
                        icon: 2,
                        time: 2000
                    });
                    return false;
                }
                $.post("{:url('Menu/addMenu')}", {
                    sendData
                }, function (e) {

                    if (e.code == 0) {
                        layer.msg(e.msg, {
                            icon: 0,
                            shade: 0.1
                        });
                        return false;
                    }

                    if (e.code == '1') {
                        parent.layer.close(index); //关闭该弹窗
                        parent.layer.msg(e.msg, {
                            icon: 1,
                            time: 2000
                        }, function () {
                            window.location.href = e.data;
                        });
                    } else {
                        parent.layer.msg(e.msg, {
                            icon: 2,
                            time: 2000
                        });
                    }
                }, 'json')

            },
            btn2: function (index, layero) {
                //按钮【按钮二】的回调
                // return false;//开启该代码可禁止点击该按钮关闭
            },
            cancel: function () {
                //右上角关闭回调
                //return false 开启该代码可禁止点击该按钮关闭
            }
        });


    }

    //删除
    function roleDel(obj, id) {
        parent.layer.alert('确认删除此条记录吗?', {
            btn: ['确认', '取消'], //按钮
        }, function () {
            $.post("{:url('Users/delUser')}", {
                id: id
            }, function (e) {
                if (e.code == '1') {
                    layer.msg(e.msg, {
                        icon: 1,
                        time: 2000,
                    });
                    $(obj).parents("tr").remove();
                    parent.layer.closeAll();
                } else {
                    layer.msg(e.msg, {
                        icon: 1,
                        time: 2000,
                    });
                }
            }, 'json');
        });
    }
    //状态开启关闭
    function role_state(obj, id) {
        $.post("{:url('Users/userEditStatus')}", {
            id: id
        }, function (e) {
            if (e.code == '1') {

                if ($(obj).find("span").hasClass("label-info")) {
                    layer.msg(e.msg, {
                        icon: 2,
                        time: 2000
                    });
                    $(obj).find("span").addClass("label-danger")
                    $(obj).find("span").removeClass("label-info");
                    $(obj).find("span").text("关闭");
                } else {
                    layer.msg(e.msg, {
                        icon: 1,
                        time: 2000
                    });
                    $(obj).find("span").removeClass("label-danger")
                    $(obj).find("span").addClass("label-info");
                    $(obj).find("span").text("开启")

                }
            } else {
                layer.msg(e.msg, {
                    icon: 0,
                    shade: 0.1
                });
                return false;
            }
        }, 'json')



    }

    /**
        * 修改排序
        */
    function ModifyTheSort(obj, id) {
        var sort = $(obj).val();
        var id = id;
        $.post("{:url('Menu/ModifyTheSort')}", {
            sort: sort,
            id: id
        }, function (e) {

        }, 'json');
    }


    /**
        * 添加菜单栏
        */

    function addMenu() {
        var sendData = {};
        var data = $("#add_rule").serialize(); //序列化表单
        data.split('&').forEach(function (param) {
            param = param.split('=');
            sendData[param[0]] = decodeURI(param[1]);
        })
        console.log(sendData);
        if ($("#title").val() == '') {
            parent.layer.msg('菜单名不能为空', {
                icon: 2,
                time: 2000
            });
            return false;
        }

        if ($("#url").val() == '') {
            parent.layer.msg('节点不能为空', {
                icon: 2,
                time: 2000
            });
            return false;
        }
        $.post("{:url('Menu/addMenu')}", {
            sendData
        }, function (e) {

            if (e.code == 0) {
                layer.msg(e.msg, {
                    icon: 0,
                    shade: 0.1
                });
                return false;
            }

            if (e.code == '1') {
                parent.layer.msg(e.msg, {
                    icon: 1,
                    time: 2000
                }, function () {
                    window.location.href = e.data;
                });
            } else {
                parent.layer.msg(e.msg, {
                    icon: 2,
                    time: 2000
                });
            }
        }, 'json')
    }
    //数据库备份

    $("input[name='all']").click(function () {
        if ($(this).is(":checked")) {
            $(".Subpage").prop("checked", true)
        } else {
            $(".Subpage").prop("checked", false)
        }
    });
    //删除
    function del(obj, time) {
        parent.layer.confirm('你确定要删除吗?', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.get("{:url('Data/del')}", {
                time: time
            }, function (data) {
                if (data.code == 1) {
                    $(obj).parents('tr').remove();
                    top.layer.msg(data.msg, {
                        icon: 1
                    });
                    parent.layer.closeAll();
                } else {
                    top.layer.msg(data.msg, {
                        icon: 2
                    });
                }
            }, 'json');
        });
    }



    // 权限菜单状态操作
    function rule_state(obj, id) {
        $.post("{:url('Menu/edit')}", {
            id: id
        }, function (e) {
            if (e.code == 1) {
                layer.msg(e.msg, {
                    icon: 1,
                    time: 2000
                });
                if ($(obj).find("span").hasClass("label-info")) {
                    $(obj).find("span").addClass("label-danger")
                    $(obj).find("span").removeClass("label-info");
                    $(obj).find("span").text("关闭");
                } else {

                    $(obj).find("span").removeClass("label-danger")
                    $(obj).find("span").addClass("label-info");
                    $(obj).find("span").text("开启")

                }
            } else {
                layer.msg(e.msg, {
                    icon: 0,
                    shade: 0.1
                });
                return false;
            }
        }, 'json')
    }

    //是否菜单
    function role_menutitle(obj, id) {
        $.post("{:url('Menu/menutitle')}", {
            id: id
        }, function (e) {
            if (e.code == '1') {
                top.layer.msg(e.msg, {
                    icon: 1,
                    time: 2000
                });
                if ($(obj).find("span").hasClass("label-info")) {
                    $(obj).find("span").addClass("label-danger")
                    $(obj).find("span").removeClass("label-info");
                    $(obj).find("span").text("否");
                } else {

                    $(obj).find("span").removeClass("label-danger")
                    $(obj).find("span").addClass("label-info");
                    $(obj).find("span").text("是")
                }
            }
        }, 'json')

    }

    // 删除菜单
    function ruleDel(obj, id) {
        parent.layer.alert('确认删除此条记录吗?', {
            btn: ['确认', '取消'], //按钮
        }, function () {
            $.post("{:url('Menu/delMenu')}", {
                id: id
            }, function (e) {
                if (e.code == '1') {
                    parent.layer.msg(e.msg, {
                        icon: 1,
                        time: 2000,
                    });
                    $(obj).parents("tr").remove();
                    parent.layer.closeAll();
                } else {
                    parent.layer.msg(e.msg, {
                        icon: 1,
                        time: 2000,
                    });
                }
            }, 'json');
        });
    }
</script>